package com.cooper.base.controller;

import com.cooper.base.service.SysRoleService;
import com.cooper.base.vo.DataTablesViewPage;
import com.cooper.common.core.db.QueryPage;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 角色Controller
 */
@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 跳转列表展示页面
     */
    @RequestMapping(value = "/list", method = {RequestMethod.GET})
    @RequiresRoles("admin")
    public String list() {
        return "ftl/role/list";
    }

    /**
     * 跳转添加页面
     */
    @RequestMapping(value = "/toAdd", method = {RequestMethod.GET})
    @RequiresRoles("admin")
    public String toAdd() {
        return "ftl/role/add";
    }

    /**
     * 跳转编辑页面
     */
    @RequestMapping(value = "/toEdit", method = {RequestMethod.GET})
    @RequiresRoles("admin")
    public String toEdit() {
        return "ftl/role/edit";
    }


    /**
     * 角色列表
     */
    @RequestMapping(value = "/ajaxList", method = {RequestMethod.POST})
    @RequiresRoles("admin")
    @ResponseBody
    public DataTablesViewPage ajaxList(String sEcho, QueryPage page) {
        return new DataTablesViewPage(sysRoleService.list(page), page, sEcho);
    }


}
